
public class StackWithMin2 {
	LinkedListNode top;
	Stack s;
	
	public StackWithMin2() {
		s = new Stack();
	}
	
	public void push(int d){
		if(s.isEmpty() || s.peek().data >= d) s.push(d);
		
		LinkedListNode n = new LinkedListNode(d);
		
		if(top == null) top = n;
		else {
			n.next = top;
			top = n;
		}
	}
	
	public int pop(){
		if(s.peek().data == top.data) s.pop();
		
		if(top == null) return Integer.MIN_VALUE;
		
		LinkedListNode n = top;
		top = top.next;
		return n.data;
	}
	
	public boolean isEmpty(){
		return top == null ? true : false; 
	}
	
	public int peek(){
		return top == null ? null : top.data;
	}
	
	public int getMin(){
		return s.isEmpty() ? Integer.MIN_VALUE : s.peek().data;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		StackWithMin2 stack = new StackWithMin2();
		stack.push(8);
		stack.push(10);
		stack.push(13);
		stack.push(2);
		stack.push(6);
		System.out.println(stack.peek());
		System.out.println(stack.isEmpty());
		System.out.println(stack.getMin());
		System.out.println(stack.pop());
		System.out.println(stack.getMin());
		System.out.println(stack.pop());
		System.out.println(stack.getMin());

	}

}
